import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    CompanyState state, Dispatch dispatch, ViewService viewService) {

  return Scaffold(
    appBar: TabBar(
      tabs: _createTabs(state, dispatch, viewService),
      controller: state.mController,
      indicatorColor: Colors.blueAccent,
      unselectedLabelColor: Colors.grey,
      labelColor: Colors.blueAccent,
      onTap: (tab) {

      },
    ),
    body: TabBarView(
      children: _createTabContentViews(state, dispatch, viewService),
      controller: state.mController,
    ),
    // floatingActionButton: FloatingActionButton(
    //   child: Icon(Icons.refresh,color: Colors.white,),
    //   onPressed: (){
    //     dispatch(CompanyActionCreator.refreshUI());
    //   },
    // ),
  );
}

List<Widget> _createTabs(
    CompanyState state, Dispatch dispatch, ViewService viewService) {
  var list = List<Widget>();
  if (state.tabNames != null) {
    state.tabNames.forEach((item) {
      // list.add(FlatButton(
      //   child: Text(item),
      //   highlightColor: Colors.blue,
      // ));

      list.add(Container(
        padding: EdgeInsets.only(left: 0, top: 8, right: 0, bottom: 8),
        child: Text(item),
      ));
    });
  }
  return list;
}

List<Widget> _createTabContentViews(
    CompanyState state, Dispatch dispatch, ViewService viewService) {
  var list = List<Widget>();
  if (state.tabNames != null) {
    // state.tabNames.forEach((item) {
    //   list.add(Container(
    //     child: viewService.buildComponent('village-access'),
    //   ));
    //   // list.add(viewService.buildComponent('village-access'));
    // });

    list.add(Container(
      child: viewService.buildComponent('village-access'),
    ));
    list.add(Container(
      child: viewService.buildComponent('village-access-card'),
    ));
    list.add(Container(
      child: viewService.buildComponent('village-grid'),
    ));
  }
  return list;
}
